<script setup>
import { useBanner } from "./composables/useBanner";
import { useCategory } from "./composables/useCategory";

const { BannerData } = useBanner();
const { CategoryData } = useCategory();
</script>

<template>
  <div class="top-category">
    <div class="container m-top-20">
      <!-- 轮播图 -->
      <div class="home-banner">
        <el-carousel height="500px">
          <el-carousel-item v-for="item in BannerData" :key="item.id">
            <img :src="item" alt="" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <!-- 全部分类 -->
      <div class="sub-list">
        <ul class="product-list">
          <li v-for="i in CategoryData" :key="i.id" class="product-item">
            <RouterLink :to="`/detail/${i.products.productId}`">
              <img :src="i.productImages[0].imageUrl" alt="" />
              <p class="product-title">{{ i.products.title }}</p>
              <p class="product-price">
                <span>￥</span>
                {{ i.products.price }}
              </p>
            </RouterLink>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.top-category {
  h3 {
    font-size: 28px;
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 100px;
  }

  /* 设置整个商品列表容器 */
  .sub-list {
    margin: 2rem auto;
    width: 100%;
  }

  /* 商品列表使用网格布局以确保每行显示6个商品 */
  .product-list {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 每行6列 */
    gap: 1rem; /* 列表项之间的间隔 */
    padding: 0;
    margin: 0;
    list-style: none;
  }

  /* 商品项样式 */
  .product-item {
    background-color: #fff; /* 卡片背景颜色 */
    padding: 1rem;
    border-radius: 8px; /* 圆角 */
    overflow: hidden; /* 确保内容不会超出卡片边界 */
    box-shadow: 0 2px 4px rgba(0, 0, 0, .1); /* 添加轻微阴影增加立体感 */
    transition: transform .2s ease-in-out; /* 添加悬停效果 */
  }

  .product-item:hover {
    transform: translateY(-5px);
  }

  /* 图片样式 */
  .product-item img {
    width: 240px;
    height: 240px;
    object-fit: cover;
    border-bottom: 1px solid #e5e5e5; /* 图片下方细线分隔 */
  }

  /* 商品标题样式 */
  .product-title {
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    color: #1f1f1f;
    display: -webkit-box;
    font-size: 16px;
    font-weight: 500;
    height: 48px;
    line-height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 224px;
    margin-top: 10px;
  }
  .product-price {
    font-size: 24px;
    height: 24px;
    line-height: 24px;
    margin-top: 10px;
    color: #ff4f24;

    span {
      font-size: 14px;
      height: 15px;
      line-height: 15px;
      position: relative;
      top: -1px;
    }
  }

  .ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;

    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }

      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }

    .body {
      display: flex;
      justify-content: space-around;
      padding: 0 40px 30px;
    }
  }

  .bread-container {
    padding: 25px 0;
  }
}

.home-banner {
  width: 1240px;
  height: 500px;
  margin: 0 auto;

  img {
    width: 100%;
    height: 500px;
  }
}
</style>
